<?php

/**
 * Menu(菜单管理)

 */
class UserAction extends AdminAction {

    /**
     *  个人会员管理
     */
    public function index() {
        $model = D('User');
        $map   = array('type' => 'user');
        $this->_list($model, $map);
        $this->display();
    }

    public function deleteUser() {
        $id = (int) $this->_get("id");
        if (M('User')->delete($id)) {
            $this->success("删除名片模版成功！");
        } else {
            $this->error("删除名片模版失败！");
        }
    }

    /**
     * 添加会员 
     */
    public function editUser() {
        $model = D('User');
        if (IS_POST) {
            if (false === $model->create()) {
                $this->error($model->getError());
            }
            $_POST['type'] = 'user';
            if ($_POST['user_id'] != false) {
                $res = $model->save($_POST);
            } else {
                $res = $model->add($_POST);
            }

            if ($res) {
                $this->success('操作成功');
            } else {
                $this->error('操作失败');
            }
        } else {
            $id   = (int) $this->_get("id");
            $data = $model->find($id);
            $this->assign('data', $data);
            $this->display();
        }
    }

    /**
     *  商户会员管理
     */
    public function shop() {
        $model = D('User');
        $map   = array('type' => 'shop');
        $this->_list($model, $map);
        $this->display();
    }

    public function active() {
        $model = D('User');
        if (IS_POST) {
            $res = $model->where(array('user_id' => $_POST['user_id']))->setField('is_active', 1);
            if($res){
                $this->success('操作成功', U('Admin/User/shop'));
            }else{
                $this->error('操作失败');
            }
        } else {
            $id   = (int) $this->_get("id");
            $data = $model->find($id);
            //商户信息
            $shop = M('Shop')->where(array('user_id' => $id))->find();
            $this->assign('shop', $shop);
            $this->assign('data', $data);
            $this->display();
        }
    }

}

?>